package com.happy.manager;

import java.util.List;
import org.nutz.dao.Dao;
import org.nutz.dao.QueryResult;
import org.nutz.dao.pager.Pager;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.Mvcs;

import com.happy.framework.asyncdb.AsyncDBService;
import com.happy.framework.asyncdb.Synchronizer;
import com.happy.bean.${tableName};
/**
*  ${db.tableNote} - 管理类，数据库操作和缓存之类的 
* @author ${author}
* @date ${dateTime}
* @version ${version}
 */
@IocBean
public class ${tableName}Manager implements Synchronizer<${tableName}> {
	public static ${tableName}Manager instance() {
		return Mvcs.getIoc().get(${tableName}Manager.class);
	}

	protected static final Log log = Logs.get();

	@Inject
	Dao dao;
	
	public ${tableName} getById(long playerId) {
		return dao.fetch(${tableName}.class, playerId);
	}
	
	public QueryResult get${tableName}sByPage(int pageNumber, int pageSize) {
		Pager pager = dao.createPager(pageNumber, pageSize);
		List<${tableName}> list = dao.query(${tableName}.class, null, pager);
		pager.setRecordCount(dao.count(${tableName}.class));
		return new QueryResult(list, pager);
	}

	public void ayncInsert(${tableName} object) {
		AsyncDBService.instance().insert(object);
	}

	public void ayncUpdate(${tableName} object) {
		AsyncDBService.instance().update(object);
	}

	public void ayncDelete(${tableName} object) {
		AsyncDBService.instance().delete(object);
	}

	@Override
	public boolean dbinsert(${tableName} object) {
		return dao.insert(object) != null;
	}

	@Override
	public boolean dbupdate(${tableName} object) {
		return dao.update(object) > 0;
	}

	@Override
	public boolean dbdelete(${tableName} object) {
		return dao.delete(object) > 0;
	}

}
